<?php
/**
 * Created by PhpStorm.
 * User: 刘红波 <liuhb@cqjcdflzxsws.com>
 * Date: 2018/8/8
 * Time: 16:15
 */

namespace app\api\controller;

use app\api\model\WeNotice;

class UserCenter extends Base
{

    /**
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $uid = $this->uid;
        $voteList = WeNotice::voteList($uid);
        $detail_list = WeNotice::detailList($uid);
//        $data['vote'] = $voteList;
//        $data['detail'] = $detail_list;
        if (isset($detail_list['data']) && isset($voteList['data'])){
            $dl = array_filter($detail_list['data'],function ($item){
                if (!empty($item)){
                    return true;
                }
            });

            $vl = array_filter($voteList['data'],function ($o){
                if (!empty($o)){
                    return true;
                }
            });
            $arr = [];

            foreach ($dl as $key => &$value) {
                foreach ($vl as $k => $item) {
                    if ($value['id'] === $item['id']) {
                        $temp = array_merge($value,$item);
                        $arr[] = $temp;
                    }
                }
                // unset($arr_1[$key]);
            }

            $temp_ids = array_column($arr, 'id');

            $dl_sub = array_filter($dl,function($o) use ($temp_ids){
                if (!in_array($o['id'], $temp_ids)) {
                    return true;
                }
            });


            $vl_sub = array_filter($vl,function($i) use ($temp_ids){
                if (!in_array($i['id'], $temp_ids)) {
                    return true;
                }
            });

            $res_arr = array_merge($arr,$dl_sub,$vl_sub);
            $time_sort_arr =array_column($res_arr,'create_time');
            array_multisort($time_sort_arr,SORT_DESC,$res_arr);

        }else{
            $vd = isset($voteList['data'])?$voteList['data']:[];
            $dd = isset($detail_list['data'])?$detail_list['data']:[];
            $res_arr = array_merge($vd,$dd);
        }
        list($this->code, $this->msg, $this->data) = [1, '消息通知获取成功', $res_arr];
        return;
    }
}